package com.taobaolite.order;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import com.taobaolite.user.User;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import javax.validation.Valid;
import java.util.List;
import java.util.function.ObjDoubleConsumer;


//@SaCheckLogin
@RestController
@RequestMapping(path = "/api/v1/order")
public class OrderController {
    private final OrderService orderService;

    @Autowired
    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @GetMapping
    public List<OrderBody> getOrder(@RequestParam Long userId, @RequestParam(required = false) Long orderId) {
        User.checkToken();
        return orderService.getOrder(userId,orderId);
    }

    @PostMapping
    public OrderBody createOrder(@RequestParam Long userId, @Valid @RequestBody OrderBody orderBody) {
        User.checkToken();
        return orderService.createOrder(userId, orderBody);
    }

    @PutMapping
    public PutItem putStatus(@RequestParam("userId") Long userId,
                             @RequestParam("orderId") Long orderId,
                             @RequestParam("action") Short action,
                             @RequestParam("status") int int_status
                             ) {
        OrderStatus status = OrderStatus.values()[int_status];
        User.checkToken();
        return orderService.putStatus(userId, orderId, action, status);
    }

//    @GetMapping("?")
}
